package priv.pront.code.lanqiao.competition.course.date0401;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @Description:
 * @Author: pront
 * @Time:2023-04-01 18:37
 */
public class Main1 {
    static int N,C,count = 0;
    static int[] arr;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        C = scanner.nextInt();
        arr = new int[N];
        for (int i = 0; i < N; i++) {
            arr[i] = scanner.nextInt();
        }
        Arrays.sort(arr);
        for (int i = N - 1; i >= 1; i--) {
            int left = 0;
            int right = i - 1;
            while (left <= right) {
                int mid = left + (right - left) / 2;
                if (arr[i] - arr[mid] < C) {
                    right = mid - 1;
                }else if(arr[i] - arr[mid] > C){
                    left = mid + 1;
                }else if(arr[i] - arr[mid] ==C){
                    int curCount = 1;
                    int curMid = mid;
                    while (curMid != N - 1 && arr[curMid] == arr[curMid + 1]) {
                        curMid = curMid + 1;
                        curCount++;
                    }
                    curMid = mid;
                    while (curMid != 0 && arr[curMid] == arr[curMid - 1]) {
                        curMid = curMid - 1;
                        curCount++;
                    }
                    count += curCount;
                    break;
                }
            }
        }
        System.out.println(count);
    }
}
